package com.project.stream_producer.demo4.service.impl;

import com.project.stream_producer.demo4.conf.MyOutPut;
import com.project.stream_producer.demo4.service.MessageDemo4Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

@EnableBinding(MyOutPut.class) //修改为自定义的配置
public class MessageDemo4ProducerImpl implements MessageDemo4Producer {

    @Autowired
    private MyOutPut myOutPut;//消息发送管道

    @Override
    public boolean send(int num,int tag) {
        boolean send=true;
        if(tag==2)
            send=myOutPut.myoutput2().send(MessageBuilder.withPayload("output_send>>"+num).build());
        if(tag==1)
            send=myOutPut.myoutput1().send(MessageBuilder.withPayload("myoutput_send>>"+num).build());
        if(tag==3) //新增kafka发送方法
            send=myOutPut.mykafkaoutput().send(MessageBuilder.withPayload("mykafka_send>>"+num).build());
        return send;
    }

}
